package com.guigu.gulimember.controller;


import com.guigu.gulicommon.entity.pojo.res.Res;
import com.guigu.gulicommon.entity.vo.MemberAddressVo;
import com.guigu.gulimember.entity.UmsMemberReceiveAddress;
import com.guigu.gulimember.service.IUmsMemberReceiveAddressService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.guigu.gulicommon.constant.enumes.res.SelectResCode.SELECT_MEMBER_RECEIVE_ADDRESS_LIST_SUCCESS;

/**
 * <p>
 * 会员收货地址 前端控制器
 * </p>
 *
 * @author 陈俊杰
 * @since 2024-08-03
 */
@RestController
@RequestMapping("/ums-member-receive-address")
public class UmsMemberReceiveAddressController {
    @Autowired
    private IUmsMemberReceiveAddressService iUmsMemberReceiveAddressService;

    /**
     * 获取会员Id收货地址列表
     */
    @GetMapping("/list")
    public Res<MemberAddressVo> list() {
        return iUmsMemberReceiveAddressService.getList();
    }

    /**
     * 根据收货地址id获取会员收货地址
     *
     * @param addrId 收货地址id
     * @return 收货地址
     */
    @GetMapping("/getById")
    public Res<MemberAddressVo> getById(@RequestParam("addrId") Long addrId) {
        UmsMemberReceiveAddress addressServiceById = iUmsMemberReceiveAddressService.getById(addrId);
        MemberAddressVo memberAddressVo = new MemberAddressVo();
        BeanUtils.copyProperties(addressServiceById, memberAddressVo);
        return new Res<>(SELECT_MEMBER_RECEIVE_ADDRESS_LIST_SUCCESS, memberAddressVo);
    }
}
